



ALTER   PROC sp_ct_forecast_save_project_details
 
 @PROGCARDCOL VARCHAR(100),
 @PLATFORMCOL VARCHAR(100), 
 @MARKETSEGMENTCOL VARCHAR(100),
 @BOARDCHIPCOL VARCHAR(50),
 @UNITSPERBOARDCOL VARCHAR(50),
 @NOOFBOARDSCOL VARCHAR(50),
 @OPPSIZECOL VARCHAR(50),
 @OPPSTATUSCOL VARCHAR(100),
 @APPLICATIONCOL VARCHAR(100),
 @CUSTOMER_NAME VARCHAR(100),
 @PART_NUMBER VARCHAR(100),
 @ENDCUSTOMER VARCHAR(100),
 @PROGCARD VARCHAR(100),
 @PLATFORM VARCHAR(100), 
 @APPLICATION VARCHAR(100),
 @MARKETSEGMENT VARCHAR(100),
 @BOARDCHIP VARCHAR(50),
 @UNITSPERBOARD VARCHAR(50),
 @NOOFBOARDS VARCHAR(50),
 @OPPSIZE VARCHAR(50),
 @OPPSTATUS VARCHAR(100),
 @REGIONALMGR VARCHAR(50),
 @PRODUCTSTATUSCOL VARCHAR(50),
 @PRODUCTIONDATECOL VARCHAR(50),
 @PRODUCTSTATUS VARCHAR(50),
 @PRODUCTIONDATE VARCHAR(20)
	 
 
 
 AS
 BEGIN
 
 	DECLARE @DB_BILLING_ADDRESS_ID  INT 
 	DECLARE @DB_SHIPPING_ADDRESS_ID INT 
 	DECLARE @DB_CUSTOMER_ID INT
 	DECLARE @CUSTID INT
	DECLARE @ODMID INT
	DECLARE @PRODID INT 	
	DECLARE @PROJID INT
	DECLARE @PROJNAME VARCHAR(100)
	DECLARE @CUSTOMER_PART VARCHAR(10)
	DECLARE @PRODUCT_PART VARCHAR(10)
	DECLARE @ENDCUST_PART VARCHAR(10)
	DECLARE @DB_PROJECT_ID INT
	DECLARE @DB_PROJNAME VARCHAR(100)
	DECLARE @TEMP_SPID INT
	DECLARE @TEMP_PRODID INT			

 	-- CUSTOMER
	IF @CUSTOMER_NAME IS NOT NULL AND LTRIM(RTRIM(@CUSTOMER_NAME)) <> ''
	BEGIN

		IF @CUSTOMER_NAME = 'NetScalar'
		BEGIN
			SET @CUSTOMER_NAME = 'NetScaler, INC.'
		END
		IF @CUSTOMER_NAME = 'Unet Systems'
		BEGIN
			SET @CUSTOMER_NAME = 'UNETSYSTEM CORP.'
		END
		IF @CUSTOMER_NAME = 'Samsung'
		BEGIN
			SET @CUSTOMER_NAME = 'Samsung Electronics'
		END
		IF @CUSTOMER_NAME = 'Huawei 3COM'
		BEGIN
			SET @CUSTOMER_NAME = 'Huawei-3COM Technologies Co., LTD.'
		END
		IF @CUSTOMER_NAME = 'Lanbird'
		BEGIN
			SET @CUSTOMER_NAME = 'LANBIRD TECHNOLOGY'
		END
		IF @CUSTOMER_NAME = 'Harbour Networks'
		BEGIN
			SET @CUSTOMER_NAME = 'Beijing HARBOUR NETWORKS'
		END
		IF @CUSTOMER_NAME = 'Shanghai UUDynamics'
		BEGIN
			SET @CUSTOMER_NAME = 'UUDYNAMICS, INC.'
		END
		IF @CUSTOMER_NAME = 'Cisco' OR @CUSTOMER_NAME = 'Secure computing' OR @CUSTOMER_NAME = 'NetScaler, INC.' OR @CUSTOMER_NAME = 'Fujitsu' OR @CUSTOMER_NAME = 'Fujitsu PFU' OR @CUSTOMER_NAME = 'Fujitsu iNET' OR @CUSTOMER_NAME = 'Hitachi CT(Daiwabo)' OR @CUSTOMER_NAME = 'Hitachi R&D' OR @CUSTOMER_NAME = 'Hitachi CT' OR @CUSTOMER_NAME = 'LANBIRD TECHNOLOGY' OR @CUSTOMER_NAME = 'Lanbird (Il Young)' OR @CUSTOMER_NAME = 'Yahoo Korea' OR @CUSTOMER_NAME = 'Huawei-3COM Technologies Co., LTD.' OR @CUSTOMER_NAME = 'Huawei Technologies' OR @CUSTOMER_NAME = 'Samsung Electronics' OR @CUSTOMER_NAME = 'SHANGHAI MAGCARD' 
		BEGIN
			SELECT @DB_CUSTOMER_ID = CUSTOMER_ID, @DB_BILLING_ADDRESS_ID = C_DEFAULT_BILLING_ADDRESS_ID, @DB_SHIPPING_ADDRESS_ID = C_DEFAULT_SHIPPING_ADDRESS_ID FROM CUSTOMER WHERE C_NAME = LTRIM(RTRIM(@CUSTOMER_NAME))
		END
		ELSE
		BEGIN
		 	SELECT @DB_CUSTOMER_ID = CUSTOMER_ID, @DB_BILLING_ADDRESS_ID = C_DEFAULT_BILLING_ADDRESS_ID, @DB_SHIPPING_ADDRESS_ID = C_DEFAULT_SHIPPING_ADDRESS_ID FROM CUSTOMER WHERE C_NAME = LTRIM(RTRIM(@CUSTOMER_NAME)) OR C_NAME LIKE ''+SUBSTRING(LTRIM(@CUSTOMER_NAME),1,5)+'%' 	
		END 
	 	IF ( @@ROWCOUNT = 0 )
	 	BEGIN	--print 'customer......................'	
	 		INSERT INTO ADDRESS ( ADDRESS_1, ADDRESS_2, CITY, STATE, ZIPCODE, COUNTRY, PHONE_NUMBER, FAX_NUMBER, EMAIL, TIMESTAMP, CONTACT_PERSON, CELL_NUMBER, ADDRESS_3, ADDRESS_4 ) VALUES ( '','','','','','','','','', CURRENT_TIMESTAMP, '','','','' )
	 		SET @DB_BILLING_ADDRESS_ID = ( SELECT @@IDENTITY )		
	 	
	 		INSERT INTO ADDRESS ( ADDRESS_1, ADDRESS_2, CITY, STATE, ZIPCODE, COUNTRY, PHONE_NUMBER, FAX_NUMBER, EMAIL, TIMESTAMP, CONTACT_PERSON, CELL_NUMBER, ADDRESS_3, ADDRESS_4 ) VALUES ( '','','','','','','','','', CURRENT_TIMESTAMP, '','','','' )
	 		SET @DB_SHIPPING_ADDRESS_ID = ( SELECT @@IDENTITY )	 	
	 
	 		INSERT INTO CUSTOMER ( C_NAME, C_DEFAULT_BILLING_ADDRESS_ID, C_DEFAULT_SHIPPING_ADDRESS_ID, C_REGION, C_REP_OFFICE, C_CUSTOM_REQUIREMENTS, C_ECN_CHANGE_NOTIFICATION, C_DISABLED) VALUES ( @CUSTOMER_NAME, @DB_BILLING_ADDRESS_ID, @DB_SHIPPING_ADDRESS_ID, '', '', 1, 1, 1) 
	 		SET @DB_CUSTOMER_ID = ( SELECT @@IDENTITY )
	 
	 		IF ( ( SELECT COUNT (*) FROM CUSTOMER_TYPE_RELATIONSHIP WHERE CUSTOMER_ID = @DB_CUSTOMER_ID  AND C_TYPE_ID = 1 ) = 0 )		
	 		BEGIN
	 			INSERT INTO CUSTOMER_TYPE_RELATIONSHIP ( CUSTOMER_ID, C_TYPE_ID ) VALUES ( @DB_CUSTOMER_ID, 1 ) 
	 		END
			SET @CUSTID = @DB_CUSTOMER_ID
	 	END
		ELSE
		BEGIN
			IF ( ( SELECT COUNT (*) FROM CUSTOMER_TYPE_RELATIONSHIP WHERE CUSTOMER_ID = @DB_CUSTOMER_ID  AND C_TYPE_ID = 1 ) = 0 )		
	 		BEGIN
	 			INSERT INTO CUSTOMER_TYPE_RELATIONSHIP ( CUSTOMER_ID, C_TYPE_ID ) VALUES ( @DB_CUSTOMER_ID, 1 ) 
	 		END
			SET @CUSTID = @DB_CUSTOMER_ID
		END
	END

	--END CUSTOMER
	SET @DB_CUSTOMER_ID = NULL
	SET @DB_BILLING_ADDRESS_ID = NULL
	SET @DB_SHIPPING_ADDRESS_ID = NULL

	IF @ENDCUSTOMER IS NULL OR LTRIM(RTRIM(@ENDCUSTOMER)) = ''
	BEGIN
		SET @ENDCUSTOMER = @CUSTOMER_NAME
	END

	IF @ENDCUSTOMER IS NOT NULL AND LTRIM(RTRIM(@ENDCUSTOMER)) <> ''
	BEGIN 

		IF @ENDCUSTOMER = 'Samsung'
		BEGIN
			SET @ENDCUSTOMER = 'Samsung Electronics'
		END
		IF @ENDCUSTOMER = 'NetScalar'
		BEGIN
			SET @ENDCUSTOMER = 'NetScaler, INC.'
		END
		IF @ENDCUSTOMER = 'Huawei 3COM'
		BEGIN
			SET @ENDCUSTOMER = 'Huawei-3COM Technologies Co., LTD.'
		END
		IF @ENDCUSTOMER = 'Lanbird'
		BEGIN
			SET @ENDCUSTOMER = 'LANBIRD TECHNOLOGY'
		END
		IF @ENDCUSTOMER = 'Harbour Networks'
		BEGIN
			SET @ENDCUSTOMER = 'Beijing HARBOUR NETWORKS'
		END
		IF @ENDCUSTOMER = 'Unet Systems'
		BEGIN
			SET @ENDCUSTOMER = 'UNETSYSTEM CORP.'
		END
		IF @ENDCUSTOMER = 'Shanghai UUDynamics'
		BEGIN
			SET @ENDCUSTOMER = 'UUDYNAMICS, INC.'
		END
		IF @ENDCUSTOMER = 'Cisco' OR @ENDCUSTOMER = 'Secure computing' OR @ENDCUSTOMER = 'Hitachi Cable' OR @ENDCUSTOMER = 'Hitachi CT' OR @ENDCUSTOMER = 'Hitachi R&D' OR @ENDCUSTOMER = 'Shanghai UTT' OR @ENDCUSTOMER = 'Shanghai Magcard' OR @ENDCUSTOMER = 'Shanghai Flexcomm' OR @ENDCUSTOMER = 'Samsung Electronics' OR @ENDCUSTOMER = 'LANBIRD TECHNOLOGY' OR @ENDCUSTOMER = 'Lanbird (Il Young)' OR @ENDCUSTOMER = 'Huawei-3COM Technologies Co., LTD.' OR @ENDCUSTOMER = 'Huawei Technologies' OR @ENDCUSTOMER = 'NetScaler, INC.' OR @ENDCUSTOMER = 'Beijing HARBOUR NETWORKS' OR @ENDCUSTOMER = 'Fujitsu' OR @ENDCUSTOMER = 'Fujitsu PFU' OR @ENDCUSTOMER = 'Fujitsu iNET' OR @ENDCUSTOMER = 'Hitachi CT(Daiwabo)' OR @ENDCUSTOMER = 'Yahoo Korea'
		BEGIN
			SELECT @DB_CUSTOMER_ID = CUSTOMER_ID, @DB_BILLING_ADDRESS_ID = C_DEFAULT_BILLING_ADDRESS_ID, @DB_SHIPPING_ADDRESS_ID = C_DEFAULT_SHIPPING_ADDRESS_ID FROM CUSTOMER WHERE C_NAME = LTRIM(RTRIM(@ENDCUSTOMER))
		END
		ELSE
		BEGIN
			SELECT @DB_CUSTOMER_ID = CUSTOMER_ID, @DB_BILLING_ADDRESS_ID = C_DEFAULT_BILLING_ADDRESS_ID, @DB_SHIPPING_ADDRESS_ID = C_DEFAULT_SHIPPING_ADDRESS_ID FROM CUSTOMER WHERE C_NAME = LTRIM(RTRIM(@ENDCUSTOMER)) OR C_NAME LIKE ''+SUBSTRING(LTRIM(@ENDCUSTOMER),1,5)+'%' 	
	 	END
	 	IF ( @@ROWCOUNT = 0 )
	 	BEGIN		
	 		INSERT INTO ADDRESS ( ADDRESS_1, ADDRESS_2, CITY, STATE, ZIPCODE, COUNTRY, PHONE_NUMBER, FAX_NUMBER, EMAIL, TIMESTAMP, CONTACT_PERSON, CELL_NUMBER, ADDRESS_3, ADDRESS_4 ) VALUES ( '','','','','','','','','', CURRENT_TIMESTAMP, '','','','' )
	 		SET @DB_BILLING_ADDRESS_ID = ( SELECT @@IDENTITY )		
	 	
	 		INSERT INTO ADDRESS ( ADDRESS_1, ADDRESS_2, CITY, STATE, ZIPCODE, COUNTRY, PHONE_NUMBER, FAX_NUMBER, EMAIL, TIMESTAMP, CONTACT_PERSON, CELL_NUMBER, ADDRESS_3, ADDRESS_4 ) VALUES ( '','','','','','','','','', CURRENT_TIMESTAMP, '','','','' )
	 		SET @DB_SHIPPING_ADDRESS_ID = ( SELECT @@IDENTITY )	 	
	 
	 		INSERT INTO CUSTOMER ( C_NAME, C_DEFAULT_BILLING_ADDRESS_ID, C_DEFAULT_SHIPPING_ADDRESS_ID, C_REGION, C_REP_OFFICE, C_CUSTOM_REQUIREMENTS, C_ECN_CHANGE_NOTIFICATION, C_DISABLED) VALUES ( @ENDCUSTOMER, @DB_BILLING_ADDRESS_ID, @DB_SHIPPING_ADDRESS_ID, '', '', 1, 1, 1) 
	 		SET @DB_CUSTOMER_ID = ( SELECT @@IDENTITY )
	 
	 		IF ( ( SELECT COUNT (*) FROM CUSTOMER_TYPE_RELATIONSHIP WHERE CUSTOMER_ID = @DB_CUSTOMER_ID  AND C_TYPE_ID = 2 ) = 0 )		
	 		BEGIN
	 			INSERT INTO CUSTOMER_TYPE_RELATIONSHIP ( CUSTOMER_ID, C_TYPE_ID ) VALUES ( @DB_CUSTOMER_ID, 2 ) 
	 		END
			SET @ODMID = @DB_CUSTOMER_ID
	 	END	
		ELSE
		BEGIN
			IF ( ( SELECT COUNT (*) FROM CUSTOMER_TYPE_RELATIONSHIP WHERE CUSTOMER_ID = @DB_CUSTOMER_ID  AND C_TYPE_ID = 2 ) = 0 )		
	 		BEGIN
	 			INSERT INTO CUSTOMER_TYPE_RELATIONSHIP ( CUSTOMER_ID, C_TYPE_ID ) VALUES ( @DB_CUSTOMER_ID, 2 ) 
	 		END
			SET @ODMID = @DB_CUSTOMER_ID
		END
	END	

	--DECLARE @customer_name VARCHAR(50)
	DECLARE @odm_customer_name VARCHAR(50)
	DECLARE @customer_Id INT
	DECLARE @odm_customer_id INT
	DECLARE @odm_customer_type_id INT
	DECLARE @active_status_id INT
	
	--SET @customer_name = @CUSTOMER_NAME 	
	SET @odm_customer_name = @ENDCUSTOMER
	
	SELECT @customer_Id 	= Customer_ID FROM CUSTOMER WHERE C_NAME = @customer_name
	SELECT @odm_customer_id = Customer_ID FROM CUSTOMER WHERE C_NAME = @odm_customer_name
	SELECT @odm_customer_type_id = C_Type_ID FROM Customer_Types WHERE C_Type_Name = 'END CUSTOMER'
	SELECT @active_status_id= RelationShipStatus_ID FROM Customer_Relationship_Status WHERE Name = 'Active'

	IF ( @customer_Id IS NOT NULL AND @odm_customer_id IS NOT NULL AND @odm_customer_type_id IS NOT NULL AND @active_status_id IS NOT NULL AND @customer_Id != @odm_customer_id )
	BEGIN
		IF ((SELECT COUNT (*) FROM CUSTOMER_TYPE_RELATIONSHIP WHERE CUSTOMER_ID = @odm_customer_id AND C_TYPE_ID = @odm_customer_type_id ) = 0 )		
		 BEGIN
			INSERT INTO CUSTOMER_TYPE_RELATIONSHIP (CUSTOMER_ID, C_TYPE_ID) VALUES ( @odm_customer_id, @odm_customer_type_id ) 
		 END
	
		IF ((SELECT COUNT (*) FROM CUSTOMER_ODM_RELATIONSHIP WHERE PARENTCUSTOMER_ID = @customer_Id AND ODMCUSTOMER_ID = @odm_customer_id ) = 0)
		 BEGIN
			INSERT INTO CUSTOMER_ODM_RELATIONSHIP (PARENTCUSTOMER_ID, ODMCUSTOMER_ID, RELATIONSHIPSTATUS_ID) VALUES (@customer_Id, @odm_customer_id, @active_status_id)
		 END
		PRINT 'RELATIONSHIP ESTABLISHED'
	END
	ELSE
	BEGIN
		PRINT 'RELATIONSHIP NOT ESTABLISHED'
	END

	--SALES PERSON INSERTION STARTS HERE

	DECLARE @DB_SPERSONID INT
	DECLARE @DB_SALESPERSON VARCHAR(100)

	--VP SALES PERSON
	SELECT @DB_SALESPERSON = SALESPERSON_NAME FROM SALES_PERSONS WHERE SALESPERSON_NAME = 'ANDY RAVA' AND DEACTIVATED = 0
	IF @@ROWCOUNT = 0
	BEGIN
		INSERT INTO SALES_PERSONS(SALESPERSON_NAME,DEACTIVATED) VALUES('ANDY RAVA',0)
	END

	--REGIONAL MANAGER SALES PERSONS 
	SET @DB_SPERSONID = NULL
	SET @DB_SALESPERSON = NULL
	
	IF LTRIM(RTRIM(@REGIONALMGR)) = 'Charie Lu'
	BEGIN
		SET @REGIONALMGR = 'Charlie Lu'
	END
	IF LTRIM(RTRIM(@REGIONALMGR)) = 'Sean Dressel'
	BEGIN
		SET @REGIONALMGR = 'Sean Dresel'
	END
	IF LTRIM(RTRIM(@REGIONALMGR)) = 'Subtotal' OR LTRIM(RTRIM(@REGIONALMGR)) = 'Quarter Total' OR LTRIM(RTRIM(@REGIONALMGR)) = 'Grand Total'
	BEGIN
		SET @REGIONALMGR = ''
	END	
	IF @REGIONALMGR IS NOT NULL AND LTRIM(RTRIM(@REGIONALMGR)) <> ''
	BEGIN
		SELECT @DB_SALESPERSON = SALESPERSON_NAME FROM SALES_PERSONS WHERE SALESPERSON_NAME = @REGIONALMGR AND DEACTIVATED = 0 
		IF @@ROWCOUNT = 0
		BEGIN
			INSERT INTO SALES_PERSONS(SALESPERSON_NAME,DEACTIVATED) VALUES(@REGIONALMGR,0)
		END
	END
	SELECT @DB_SPERSONID = SALESPERSON_ID FROM SALES_PERSONS WHERE SALESPERSON_NAME = @REGIONALMGR AND DEACTIVATED = 0


	--SELECT @CUSTID = CUSTOMER_ID FROM CUSTOMER WHERE C_NAME LIKE @CUSTOMER_NAME --OR C_NAME LIKE ''+SUBSTRING(LTRIM(@CUSTOMER_NAME),1,5)+'%'
	--SELECT @ODMID = CUSTOMER_ID FROM CUSTOMER WHERE C_NAME = @ENDCUSTOMER --OR C_NAME LIKE ''+SUBSTRING(LTRIM(@ENDCUSTOMER),1,5)+'%'
	--SELECT @PRODID = PRODUCT_ID FROM PRODUCT WHERE PART_NUMBER = @PART_NUMBER
	SELECT @PRODID =  PRODUCT_ID FROM PRODUCT P, PROCESS_STEP PS WHERE P.PROCESSSTEP_ID = PS.PROCESSSTEP_ID AND PART_NUMBER = @PART_NUMBER AND PS_TYPE_NAME LIKE 'FINISHED GOODS' 
	IF( @@ROWCOUNT <> 0 )
	BEGIN
		--SET @PRODUCTIONDATE = CONVERT(DATETIME,@PRODUCTIONDATE)
		--SELECT @CUSTOMER_PART = SUBSTRING(@CUSTOMER_NAME,1,4)
		--SELECT @ENDCUST_PART = SUBSTRING(@ENDCUSTOMER, 1,4)
		--SET @PROJNAME = @CUSTOMER_PART+'-'+@ENDCUST_PART+'-'+@PART_NUMBER	
		SET @PROJNAME = @PROGCARD
		/*IF @PROJNAME = ''
		BEGIN
			SET @PROJNAME = 'Unknown'
		END*/
		IF @PROJNAME IS NOT NULL AND LTRIM(RTRIM(@PROJNAME)) <> ''
		BEGIN
			/*IF @PROJNAME = 'Unknown' OR @PROJNAME = 'Security Appliance' OR @PROJNAME = 'Octeon Project' OR @PROJNAME = 'Eval'  
			BEGIN		
				SELECT @DB_PROJNAME = PROJNAME, @PROJID = PROJID FROM PROJSETUP WHERE PROJNAME LIKE @PROJNAME AND SPERSONID = @DB_SPERSONID
			END
			ELSE
			BEGIN*/
				SELECT @DB_PROJNAME = PROJNAME, @PROJID = PROJID FROM PROJSETUP WHERE PROJNAME LIKE @PROJNAME
			--END
			IF( @@ROWCOUNT = 0 )
			BEGIN
				INSERT INTO PROJSETUP(PROJNAME,CUSTID,PROJSTATUS,USERTXT1,USERTXT2,USERLIST1,USERLIST2,USERLIST3,USERTXT3,USERTXT4,USERTXT5,USERLIST4,USERLIST1VAL,USERLIST2VAL,USERLIST3VAL,USERLIST4VAL,USERLIST5,USERDATE1,USERLIST5VAL, ODMID, SPERSONID) VALUES(@PROJNAME,@CUSTID,@PRODUCTSTATUS,@PROGCARDCOL,@PLATFORMCOL,@APPLICATIONCOL,@MARKETSEGMENTCOL,@BOARDCHIPCOL,@UNITSPERBOARDCOL,@NOOFBOARDSCOL,@OPPSIZECOL,@OPPSTATUSCOL,@APPLICATION,@MARKETSEGMENT,@BOARDCHIP,@OPPSTATUS,@PRODUCTSTATUSCOL,@PRODUCTIONDATECOL,@PRODUCTSTATUS,@ODMID, @DB_SPERSONID )
				SET @DB_PROJECT_ID = ( SELECT @@IDENTITY )	
				INSERT INTO PROJPRODREL(PROJID,PRODID) VALUES(@DB_PROJECT_ID,@PRODID)
				INSERT INTO FCUENTRYVAL(TABLENAME,ENTRYNAME,ENTRYVALUE,PROJID) VALUES('PROJSETUP',@PROGCARDCOL,@PROGCARD,@DB_PROJECT_ID)
				INSERT INTO FCUENTRYVAL(TABLENAME,ENTRYNAME,ENTRYVALUE,PROJID) VALUES('PROJSETUP',@PLATFORMCOL,@PLATFORM,@DB_PROJECT_ID)
				INSERT INTO FCUENTRYVAL(TABLENAME,ENTRYNAME,ENTRYVALUE,PROJID) VALUES('PROJSETUP',@APPLICATIONCOL,@APPLICATION,@DB_PROJECT_ID)
				INSERT INTO FCUENTRYVAL(TABLENAME,ENTRYNAME,ENTRYVALUE,PROJID) VALUES('PROJSETUP',@MARKETSEGMENTCOL,@MARKETSEGMENT,@DB_PROJECT_ID)
				INSERT INTO FCUENTRYVAL(TABLENAME,ENTRYNAME,ENTRYVALUE,PROJID) VALUES('PROJSETUP',@BOARDCHIPCOL,@BOARDCHIP,@DB_PROJECT_ID)
				INSERT INTO FCUENTRYVAL(TABLENAME,ENTRYNAME,ENTRYVALUE,PROJID) VALUES('PROJSETUP',@UNITSPERBOARDCOL,@UNITSPERBOARD,@DB_PROJECT_ID)
				INSERT INTO FCUENTRYVAL(TABLENAME,ENTRYNAME,ENTRYVALUE,PROJID) VALUES('PROJSETUP',@NOOFBOARDSCOL,@NOOFBOARDS,@DB_PROJECT_ID)
				INSERT INTO FCUENTRYVAL(TABLENAME,ENTRYNAME,ENTRYVALUE,PROJID) VALUES('PROJSETUP',@OPPSIZECOL,@OPPSIZE,@DB_PROJECT_ID)
				INSERT INTO FCUENTRYVAL(TABLENAME,ENTRYNAME,ENTRYVALUE,PROJID) VALUES('PROJSETUP',@OPPSTATUSCOL,@OPPSTATUS,@DB_PROJECT_ID)
				INSERT INTO FCUENTRYVAL(TABLENAME,ENTRYNAME,ENTRYVALUE,PROJID) VALUES('PROJSETUP',@PRODUCTSTATUSCOL,@PRODUCTSTATUS,@DB_PROJECT_ID)		
				INSERT INTO FCUENTRYVAL(TABLENAME,ENTRYNAME,ENTRYVALUE,PROJID) VALUES('PROJSETUP',@PRODUCTIONDATECOL,@PRODUCTIONDATE,@DB_PROJECT_ID)		
			END
			ELSE
			BEGIN
				SELECT @TEMP_SPID = SPERSONID FROM PROJSETUP WHERE PROJID = @PROJID AND SPERSONID = @DB_SPERSONID
				IF( @@ROWCOUNT <> 0 )
				BEGIN
					SELECT @TEMP_PRODID = PRODID FROM PROJPRODREL WHERE PROJID = @PROJID AND PRODID = @PRODID
					IF( @@ROWCOUNT = 0 )
					BEGIN
						INSERT INTO PROJPRODREL(PROJID,PRODID) VALUES(@PROJID,@PRODID)				
					END
				END
			END
			
		END
	END

 
 END 



